<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <div class="app">
        <h1>{{title}}</h1>
        <parent></parent>
    </div>
    <template id="parent">
        <div>
            <h1>父元素的数据-{{name}}-{{age}}</h1>
            <input type="text" value="name" v-model="name">
            <button @click="changeage">点击我修改子元素</button>
            <childone ref="one"></childone>
        </div>
    </template>
    <template id="childone">
        <div>
            <h3>父元素传来的数据-{{name}}-{{age}}</h3>   
        </div>
    </template>
    <script>
        Vue.component("parent", {
            template: "#parent",
            data() {
                return {
                    name: "不吃鱼的猫",
                    age: 18
                }
            },
            methods: {
                changeage() {
                    this.$refs.one.age += 5
                }
            }
        })
        Vue.component("childone", {
            template: "#childone",

            data() {
                return {
                    name: "可乐",
                    age: 20
                }
            }
        })

        const vm = new Vue({
            data: {
                title: "父传子ref"
            }
        }).$mount(".app")
    </script>
</body>

</html>